
* data
use "data/inputs/MunicipioData_AD_Chavez.dta", clear

* save correlation with AD 1958
mat results = J(11, 2, 0)
local i = 1
foreach year of numlist 1963(5)1998 2000(6)2012 {
	cap cor share_presAD1958 share_presAD`year'
	if _rc == 0 {
	mat results[`i',1] = `year'
	mat results[`i',2] = `r(rho)'
	}
	else {
	cor share_presAD1958 share_presOFIC`year'
	mat results[`i',1] = `year'
	mat results[`i',2] = `r(rho)'
	}
	local i = `i' + 1
}

* use results
clear 
svmat results
rename results1 year
rename results2 cor1958

* Figure 1
#delimit;
twoway (connected cor1958 year if year > 1958, 
	    lcolor(white) mcolor(white) 
	    mlwidth(thick) mlcolor(white) msize(large))
		
	   (connected cor1958 year if year >= 1963 & year <= 2012, 
	    lcolor(black) mcolor(black) lwidth(medthick)
	    mlwidth(thick) mlcolor(white) msize(large))
		
	   (scatter cor1958 year if year == 1963, 
	    mcolor(black) 
	    mlwidth(thick) mlcolor(white) msize(large))
		
	   (scatter cor1958 year if year >= 1998 & year <= 2012, 
	    lcolor(black) mcolor(black) lwidth(medthick) msymbol(diamond)
	    mlwidth(thick) mlcolor(white) msize(large))
		
   	   (scatter cor1958 year if year == 1998, 
	    lcolor(black) mcolor(blue) msymbol(diamond)
	    mlwidth(thick) mlcolor(white) msize(large)),

		yline(0, lwidth(thick) lcolor(gs12))
		graphregion(fcolor(white) lcolor(white) margin(zero))
        plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none))
        xsize(11) ysize(7.75)	
		title("", size(large))
		ytitle("Correlation with 1958 AD vote share", color(black) size(large))
		xtitle("")
		yscale()
		ylabel(-.2(.2)1, labsize(large) glcolor(white) angle(horizontal))
		xlabel(1958 "1958"
		1968 "1968"
		1978 "1978"
		1988 "1988"
		1998 "98  "
		2000 "  00"
		2006 "2006"
		2012 "2012", labsize(large))
		xscale( range(1958 2014))
        legend(order(3 "AD vs. AD 1958" 4 "Chávez vs. AD 1958") pos(8) ring(0) rows(2) 		  region(lcolor(white)));

graph export "figures/Figure1.pdf", replace;


* End
